﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json;

namespace Auto_Buy.Component
{
    public class UserLogin
    {
        public static async Task<LoginResult> Login(string phone, string pswd)
        {

            var body = new RequestBody();
            body.Method = "Login";
            var d = JsonConvert.SerializeObject(new { phone , pswd });
            body.Data = d;
            
            var respone = await HttpUnit.Post(body);
            if (respone.IsSuccessStatusCode)
            {
                var res = await respone.Content.ReadAsStringAsync();
                var obj = JsonConvert.DeserializeObject<dynamic>(res);
                var data = JsonConvert.DeserializeObject<LoginResult>(obj.d.ToString());
                return data;
            }
            Console.WriteLine("http error");
            return null;
 
        }
    }
}
